﻿<?php $access  = array('founder','superadmin');
foreach($followers as $faccess){
$follower_access[] = $faccess->user_id;	
}
?>
<?php if($this->ion_auth->is_admin()): ?>
<ul class="breadcrumb">
  <li><a href="<?= site_url('user/tasks/projects_details')?>">All Projects</a> <span class="divider">/</span></li>
  <li><a href="<?= site_url('user/tasks/milestones_details').'/'.$tasks['project_id'] ?>"><?= $tasks['name']; ?></a> <span class="divider">/</span></li>
  <li><?php  
  $task = $this->common_model->get_taskgroupname_by_id($tasks['taskgroup_id']);
  echo $task['name']
  ?><span class="divider">/</span></li>  
  <li class="active"><?= $tasks['title']; ?></li>
</ul>
<?php else:?>
<ul class="breadcrumb"> 
  <li><a href="<?= site_url('user/tasks/milestones_details').'/'.$tasks['project_id'] ?>"><?= $tasks['name']; ?></a> <span class="divider">/</span></li>
  <li><?php  
  $task = $this->common_model->get_taskgroupname_by_id($tasks['taskgroup_id']);
  echo $task['name'];
  ?><span class="divider">/</span></li>  
  <li class="active"><?= $tasks['title']; ?></li>
</ul>
<?php endif; ?>
<div class="row-fluid">
<div class="span10">
<?php
$tasks_msg = $this->session->flashdata('tasks_msg');
if(!empty($tasks_msg)){
?>
<div class="alert alert-info">
	<?= $tasks_msg?>	
</div>
<?php }?>
<h4 class="widget-name"> <i class="icon-tasks"></i> &nbsp; <?= $tasks['title']; ?></h4>
<table width="100%" class="table-condenesed">
  <tr>
    <td colspan="3" valign="bottom">
    <small class="muted" id="completed"></small>
    <div class="progress progress-danger  progress-striped active">
      <div class="bar" style="width:0%" id="bars"></div>
  </div></td>
  <?php if(empty($subtasks)) {?>
    <td width="12%" valign="bottom"><button type="button" class="btn btn-info btn-small" id="achieved">Achieved</button>
  </td>
  <?php }?>
    <td width="11%" valign="bottom"><a href="javascript:void(0)" class="btn btn-small btn-danger" id="closed">Close</a></td>
  </tr>
  <tr>
  <?php if(!$this->ion_auth->is_client()){?>
    <td width="20%"><strong>Final Due Date :</strong>  <?=$tasks['end_date'];?></td>
	<?php if($tasks['created_by']>0) {?>
	<td width="20%">
	<strong>Created by : </strong><?= ucfirst($this->common_model->get_username_id($tasks['created_by']))?>
	</td>
    <?php }?>	
	<td align="right" width="20%"><strong>Assigned to : </strong></td>	
    <td align="left"><?php
	echo ucfirst($this->common_model->get_username_id($tasks['user_id']));
	?></td>
	<?php }?>
  </tr>
</table>
<div>
<hr />
<h4>Task Description</h4>
<?= $tasks['desc'];?>	
</div>
<?if($this->session->flashdata('worsheet_msg')){?>
<div class="alert alert-error">
	<?= $this->session->flashdata('worsheet_msg')?>	
</div>
<?}?>
<hr style="margin:0" />

<div id="multisubtask" style="display:none;">
<h4>Add Multiple Subtasks</h4>
<div class="row-fluid">
<form action="<?php echo site_url('user/tasks/insert_multiple_subtask');?>" id="multiple_form" method="POST">
	<div class="span12" style="margin:0">
		<input type="hidden" value="<?php echo $tasks['id'];?>" name="mtask_id"/>
		<input type="text" class="span9 multiple_subtask" id="ms0" name="m_subtask[0]" placeholder="(Delete) - To delete a row (Enter) - For new row"/> 
		<input type="text" class="span1 multiple_subtask" name="hr[0]" id="hr" value="00"/> : 
		<input type="text" class="span1 multiple_subtask" name="min[0]" id="min" value="00"/> : 
		<input type="text" class="span1 multiple_subtask" name="sec[0]" id="sec" value="00"/>		
		<div id="insert_subtask""></div>		
		<input type="button" value="Save All Multiple Task" class="btn btn-warning btn-small" id="save_multiple" />
	</div>
	</form>
</div></div>
<br />


<!--Tabs-->


<h4 class="widget-name">Subtasks <small class="badge badge-info" id="subtask">
<?php $count = 0;
foreach($subtasks as $subtask)
{
if($subtask->is_heading==0){
	$count = $count+1;
}
}
echo $count;
?>
</small>
<small class="pull-right label label-important" >
<a href="javascript:void(0)" onclick="show_multi()" style="color:#fff">
<i class="icon-plus-sign"></i> Add Multiple Subtasks
</a>
</small>
</h4>
 <div id="contentLeft">
<ul class="ui-sortable" style="list-style:none;margin:0;">
<?php
if(empty($subtasks))
{?>
No Subtask has been added 
<?php }
else {
$i = 0;	
?>
<?php foreach($subtasks as $subtask){?>
<li id="recordsArray_<?= $subtask->id?>" class="<?php echo ($subtask->is_achieved==1)? 'achieved_pattern':''?>"  >
<div class="row-fluid <?php if($subtask->is_heading==0){?>borders <?php }?>">

<div class="span10">

<?php if($subtask->is_heading==0){?>
<div class="flag_image tooltips <?php if($subtask->is_achieved=='0'){if(!$subtask->priority) { echo "none";} else {echo $subtask->priority;}} ?>" data-toggle="tooltip" title="Click and Drag for Reordering subtasks" data-placement="left" >

<div><?= $i=$i+1;?></div>
</div>  
<?php  } else {?>

<div class="flag_image tooltips subtask_heading" data-toggle="tooltip" title="Click and Drag for Reordering subtasks" data-placement="left" >
<?= $subtask->desc?>&nbsp;
<span class="subtask_heading_edit">
<a href="<?=site_url('user/tasks/delete_subheading/'.$subtask->id.'/'.$tasks['id'])?>" onclick="return confirm('Are you sure you Delete Press [Cancel] not to delete.')"><i class="icon-trash"></i></a>
</span>
</div>
<?php }?>
<input type="hidden" value="<?=$subtask->id?>" id="subtask_id<?=$subtask->id?>" />
<?php if($subtask->is_heading==0){?>
<?= $subtask->desc?>
<?php }?>
</div>
<div class="span1">
<?php if($subtask->is_heading==0){?>
<?php echo $subtask->time_spent; ?>
</div>
<div class="span1" style="margin-left: 3px">
<div class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cogs"></i>
  <b class="caret"></b>
  </a>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
  <li><a id="<?= $subtask->id?>" onclick="achieve(this.id)" style="cursor:pointer" ><i class="icon-ok-sign"></i> <span class="text-error">Mark As Achieved</span></a></li>  
   <!-- dropdown menu links -->
   <?php if(!$this->ion_auth->is_client()){?>
	<li><a href="<?=site_url('user/tasks/get_subtask_for_worksheet/'.$subtask->id.'/'.$tasks['id'])?>" class="add_worksheet"><i class="icon-plus-sign"></i>  Add to worksheet</a></li>
	<li><a href="<?=site_url('user/tasks/get_subtask_for_todo/'.$subtask->id.'/'.$tasks['id'])?>" class="add_todo"><i class="icon-plus-sign"></i>  Add to to-do</a></li>
	<li class="divider"></li>
	<?php }?>
	<li><a href="<?=site_url('user/tasks/edit_subtask/'.$subtask->id)?>" title="Edit - <?= $subtask->desc?>" class="edit_subtasks " ><i class="icon-edit"></i> Edit</a> </li>
	<li><a href="<?=site_url('user/tasks/move_trash_subtask/'.$tasks['id'].'/'.$subtask->id)?>" title="Trash - <?= $subtask->desc?>" onclick="return confirm('Are you sure you Trash this Subtask ??')" ><i class="icon-bitbucket"></i> Trash</a></li>
	<?php 
if($this->session->userdata('user_id') == $subtask->user_id || $this->ion_auth->in_group($access)) {?>
<li><a href="<?=site_url('user/tasks/delete_subtask/'.$tasks['id'].'/'.$subtask->id)?>" title="Delete - <?= $subtask->desc?>" onclick="return confirm('Are you sure you Delete Press [Cancel] not to delete.')" ><i class="icon-trash"></i> Delete</a></li>
<?php }?>
  </ul>
  <small class="tooltips pull-right" title="Add discussion" > 
  <a href="javascript:void(0)" onclick="open_discuss(this.rel)" rel="<?php echo site_url('user/tasks/special_notes/'.$subtask->id.'#last')?>"> <i class="icon-file-text-alt"> 
  <small> <?php echo count($this->task_model->get_special_notes($subtask->id));?></small> </i></a>
  </small>
</div>
</div>
</div>
</li> 
<?php } } }?>
 </ul>
</div>
<?php if(!$this->ion_auth->is_client()){?>
<div class="trash">
	<h5 class="text-error">Trash</h5>
	<ul style="list-style: none" class="muted">
	<?php foreach($trashed_subtasks as $ts): ?>
	<li>
	<?php echo $ts->desc;?>
	<span class="pull-right">
	<span class="text-warning">[<?php echo $ts->time_spent;?>]</span>
	<a href="<?=site_url('user/tasks/restore_trash_subtask/'.$tasks['id'].'/'.$ts->id)?>" class="text-info"> <i class="icon-retweet"></i> Restore </a>		
	</span>
	
	</li>
	<?php endforeach;?>
		
	</ul>
</div>
<?php }?>


<!-- Drag n drop code ends here -->
<br /><br />

<ul id="myTab" class="nav nav-tabs">
    <li class="active">
		<a href="#comments" data-toggle="tab"> <i class="icon-comment"></i> Comments</a>
	</li>    
	<li>
		<a href="#Feedback" data-toggle="tab"> <i class=" icon-thumbs-up"></i> Feedback</a>
	</li>   
</ul>

<div id="myTabContent" class="tab-content">

    <div class="tab-pane fade in active" id="comments">
        <p>
			
			<div class="well">
<h5><i class="icon-comments icon-large"></i>  Add Comment to this Task 
<span class="pull-right">
<select id="note_type" name="note_type" <?php if($this->ion_auth->is_client()){?> style="display:none;" <?php }?> >
<option value="0">Public Comment</option>	
<option value="1">Private Comment</option>
<option value="2">Client Question</option>
</select> 
</span> 
</h5>
<br />
<small>You might enter a comment about a call, or a meeting, or a conversation you just had with this person. Notes are great for keeping a history of your interactions or communications with someone.</small>
<br />
<br />

<label>
<textarea rows="5" cols="5" class="span12" name="note" id="note"></textarea>
<span class="text-error"><?=form_error('note')?></span>
</label>
<input type="hidden" value="<?=$task_id?>" name="task_id" id="task_id" />

<input type="button" value="Add Note" class="btn btn-success pull-right"  id="submit_note" />
<br/>
</div>
<?php if($this->session->flashdata('note_message')) {?>
<div id="alert" class="alert alert-success">
<?= $this->session->flashdata('note_message') ?>
</div>
<?php }?>
<div >
<?php if(empty($notes)) {?>
<small >No Notes Till Now</small>
<?php } else {?>
<table width="100%" style="font-size:11px">
<?php foreach($notes as $note) {
	
	if( ($this->ion_auth->is_client() AND $note->note_type == 0 OR $note->note_type == 2 ) OR (!$this->ion_auth->is_client()) )
	{	
?>
 <tr>
    <td width=8%" rowspan="3" valign="top">
    <?php if(!$note->profile_image) {?>
    <img class="img-polaroid" width="48" src="<?= $this->config->base_url(); ?>assets/images/users.png" />    
	<?php } else {?>
    <img class="img-polaroid" width="48" src="<?= $this->config->base_url(); ?>assets/uploads/<?= $note->profile_image?>" />    
	<?php }?>    
    </td>
    <td width="90%">
	<strong>Comment by</strong> :	
	<?php 
	if(($this->ion_auth->is_client()) AND ($note->user_id != $this->session->userdata('user_id')))
	{
		echo "Fedobe";
	}
	else{
	echo $note->username;	
	}
	
	?>
	<span class="muted">
	<?php
	if($note->note_type == '0'){
		
	}elseif($note->note_type == '2'){
		echo '(Client Question)';
	}
	else{
		echo '(Private Message)';	
	}?>
		
	</span>
    <?php if($note->user_id == $this->session->userdata('user_id') || $this->ion_auth->in_group($access)) {?>
    <span class="pull-right">
	<a onclick="add_fav(this.name)" style="cursor:pointer" name="<?php echo $note->id?>" class="tooltips" title="Add to favourite" data-placement="top"> <i class="icon-star"></i> </a>
	&nbsp;&nbsp;
	<a href="<?= site_url('user/tasks/edit_note').'/'.$note->id.'/'.$tasks['id'];?>" rel="tooltip" class="edit_note tooltips" data-placement="bottom" title="Edit this Note"><i class="icon-edit"></i></a>	&nbsp;
	<a href="<?= site_url('user/tasks/delete_note').'/'.$note->id.'/'.$tasks['id'];?>" ><i class="icon-trash "></i></a>	
	</span>
    <?php }?>
    </td>
  </tr>
  <tr>
    <td class="muted">on <?php 
//	$date = date('Y-m-d H:i:s');
	//$date = date('c', strtotime($date));
	/*$date = date('c',strtotime($note->date));*/
	echo $note->date?></td>
  </tr>
  <tr>
    <td>
	<?= $note->note;?>
	<br />
	<small>
	<span class="span2"> 
	<?php $replies = $this->task_model->get_notes_replies($note->id);?>
	<a onclick="reply(this.name)" style="cursor:pointer" name="<?php echo $note->id?>"><i class="icon-reply"></i> <span class=""> <?= count($replies)?> </span>
	
	<?php if(count($replies) > 0) {
		echo "Replies";
		}
		else{
			echo 'Reply';
		}
		?>
	 
	 </a>	</span>
	
	</small>
	<br />
	<div id="reply_area<?php echo $note->id?>" style="display:none" >
	<textarea class="span12" id="reply_desc<?php echo $note->id?>" placeholder="write a reply ..."></textarea>
	<input type="button" class="btn btn-small btn-info" value="Reply" onclick="add_reply(<?php echo $note->id?>)" />
	 <span id="spinner" style="display:none"> <img class="" width="16" src="<?= $this->config->base_url(); ?>assets/img/loading/spinner.gif" /></span>
	</div>	
	
	</td>
  </tr>
  <tr>
  	<td></td>
	<td>
	<hr style="margin: 0"/>
	<?php 	
	foreach($replies as $reply){		
	?>
	<div class="row-fluid" style="background-color:#faf4ff" >
		<div class="span1">
		 <?php if(!$reply->profile_image) {?>
    <img class="img-polaroid" width="28" src="<?= $this->config->base_url(); ?>assets/images/users.png" />    
	<?php } else {?>
    <img class="img-polaroid" width="28" src="<?= $this->config->base_url(); ?>assets/uploads/<?= $reply->profile_image?>" />    
	<?php }?> 	
		</div>		
		<div class="span10" style="margin-left: 0px;">
			<span class="text-info"><b>			
			<?php
			if(($this->ion_auth->is_client()) AND ($reply->user_id != $this->session->userdata('user_id')))
			{
			echo "Fedobe";
			}
			else{
			echo ucfirst($reply->username);	
			}
			 ?> 
			</b></span>
			<?= $reply->reply?>
			<br />
			<span class="muted"><?= 'on'.$reply->timestamp?></span>
			
			<hr style="margin: 0"/>
		</div>
		<div class="span1">
		<?php if($this->session->userdata('user_id') == $reply->user_id || $this->ion_auth->in_group($access)) {?>
			<a href="<?php echo site_url('user/tasks/delete_reply/'.$tasks['id'].'/'.$reply->id)?>" onclick="return confirm('Are you sure you Delete? Press [Cancel] not to delete.')" > <i class="icon-trash"></i> </a>
			<?}?>
		</div>
	</div>
	
	<?php }?>
	<hr style="margin: 0"/>
		<?php ?>
		<?php ?>
	</td>
	<!-- <hr style="margin: 0"/>-->
  </tr>
 
<?php }} ?>
</table>
<?php }?>
</div>
			
		</p>		
    </div>
	<div class="tab-pane fade" id="Feedback">		
		<table class="" width="100%">				
		<?php foreach($feedbacks as $feedback){?>		
			<tr>
				<td width="5%" valign="top"><img height="32" width="32" src="<?php echo base_url()?>assets/images/smileys/<?php echo $feedback->emotion?>.png" /></td>
				<td>
				<?php if( $this->session->userdata('user_id') == $feedback->user_id){ ?>
				<a href="javascript:void(0)" rel="<?php echo $feedback->id?>" class="pull-right delete_feedback"><i class="icon-trash"></i></a>	
				<?php }?>
				<?php echo $feedback->feedback; ?><br />
				<small> by <?php echo $this->common_model->get_username_id($feedback->for) ?> <span class="muted"> on : <?php echo $feedback->timestamp?> </span> </small>
				<hr />
				</td>				
			</tr>				
		<?php }?>	
		</table>		
    </div>
</div>

</div>
<div class="span2">
<h4 class="widget-name"><i class="icon-cog"></i> Actions</h4>
<i class="icon-plus"></i> <a href="#myModal" role="button" data-toggle="modal">Add New Sub Tasks</a>
<br />
<i class="icon-plus-sign"></i> <a href="#subtask_heading" role="button" data-toggle="modal">Add Subtask Heading</a>
<br />
<?php
//print_r($follower_access);
if($tasks['user_id'] == $this->session->userdata('user_id') OR ($this->ion_auth->in_group($access)) ) {?>
<i class="icon-pencil"></i> <a href="<?= site_url('user/tasks/edit').'/'.$tasks['id']?>">Edit This Task</a><br />
<i class="icon-trash"></i> <a href="<?= site_url('user/tasks/delete_task').'/'.$tasks['id'].'/'.$tasks['project_id']?>" onclick="return confirm('Are you sure you want to DELETE this task ??')">Delete This Task</a>
<?php }?>
<br /><br />
<!--Timer -->
<h4 class="widget-name"><i class="icon-time"></i> Time spent</h4>
<?php 
$time = explode(':',$tasks['time_spent']);
if($this->ion_auth->is_client()) { 
?>
<div class="lead" align="center"><?php echo $time[0].' hr : '.$time[1].' min';?></div>

<?php }else { ?>
<input type="hidden" class=""  id="" value=""/>
<input type="text" class="span3" placeholder="hr" id="hr" value="<?php echo $time[0]?>"/> : 
<input type="text" class="span3" placeholder="min" id="min" value="<?php echo $time[1]?>"/> : 
<input type="text" class="span3" placeholder="sec" id="sec" value="<?php echo $time[2]?>"/>
<?php }?>
<br /><br />
<h4 class="widget-name"><i class=" icon-thumbs-up"></i> Give Feedback</h4>

<div class="row-fluid">
	<div class="span3">
	<?php if($this->ion_auth->is_admin() OR $this->ion_auth->is_client()) {?>
	<a href="<?=site_url('user/tasks/feedback/'.$tasks['id'].'/'.$tasks['user_id'].'/happy' )?>" class="feedback">	
	<img src="<?php echo base_url().'assets/images/smileys/happy.png'?>" style="cursor: pointer"   />
	</a>
	<?php }else {?>
	<img src="<?php echo base_url().'assets/images/smileys/happy.png'?>" style="cursor: pointer"   />
	<?php }?>
	</div>
	<div class="span3 offset1">	
	<?php if($this->ion_auth->is_admin() OR $this->ion_auth->is_client()) {?>
		<a href="<?=site_url('user/tasks/feedback/'.$tasks['id'].'/'.$tasks['user_id'].'/frown' )?>" class="feedback">
		<img src="<?php echo base_url().'assets/images/smileys/frown.png'?>" style="cursor: pointer"  /></a>	
		<?php }else {?>
		<img src="<?php echo base_url().'assets/images/smileys/frown.png'?>" style="cursor: pointer"  /></a>	
		<?php }?>
	</div>
	<div class="span3 offset1">
	<?php if($this->ion_auth->is_admin() OR $this->ion_auth->is_client()) {?>
		<a href="<?=site_url('user/tasks/feedback/'.$tasks['id'].'/'.$tasks['user_id'].'/sad' )?>" class="feedback">
		<img src="<?php echo base_url().'assets/images/smileys/sad.png'?>" style="cursor: pointer"/></a>
		<?php }else {?>
		<img src="<?php echo base_url().'assets/images/smileys/sad.png'?>" style="cursor: pointer"  /></a>
		<?php }?>
	</div>
</div> 

<?php
if(!empty($feedback_percentage)){
$feed_total = ($feedback_percentage['happy'] + $feedback_percentage['sad']+$feedback_percentage['frown']);
$happy = (($feedback_percentage['happy']/$feed_total)*100);
$sad = (($feedback_percentage['sad'] /$feed_total)*100);
$frown = (($feedback_percentage['frown'] /$feed_total)*100);
?>
<div class="progress" style="height:10px;margin-top: 10px; cursor: pointer;">
  <div class="bar bar-success tooltips" title="<?= round($happy,2);?>% Happy" style="width: <?= $happy;?>%;"></div>
  <div class="bar bar-warning tooltips" data-placement="left" title="<?= round($frown,2);?>% Frown" style="width: <?= $frown;?>%;"></div>
   <div class="bar bar-danger tooltips" data-placement="left" title="<?= round($sad,2);?>% Sad" style="width: <?= $sad;?>%;"></div>  
</div>
<?php }?>
<br />
<h4 class="widget-name"><i class=" icon-tags"></i> Followers</h4>
<div class="row-fluid">
<div class="span12">
<?php 
if ($followers){
foreach($followers as $follower){
	$follows[] = $follower->user_id;	
	?>

<div class="label label-info" id="follower<?php echo $follower->id;?>" data-username="<?php echo $follower->username;?>"> <?php echo $follower->first_name;?> 
  <?php if( ($this->ion_auth->is_admin($this->session->userdata('user_id'))) OR ($tasks['user_id'] == $this->session->userdata('user_id')) ){ 
  
  ?>
  <i class="icon-remove" style="cursor:pointer" onclick="remove_follower(<?php echo $follower->id;?>,<?php echo $follower->user_id;?>)"></i>
  <?php }?>
  </div>

<?php }}?>
</div>

<?php if( ($this->ion_auth->is_admin($this->session->userdata('user_id'))) OR ($tasks['user_id'] == $this->session->userdata('user_id')) ){ ?>
<div class="span12">
<strong> Add New Follower </strong>
<form action="<?php echo site_url('user/tasks/add_follower/'.$tasks['id'])?>" method="POST">
<select name="follower[]" class="span12" multiple="multiple" id="followers">
	<?php
	$follows[] = 0;
	 foreach($users as $user) {
		// check whether user is not client and not a follower
		if(!in_array($user->id,$follows) AND !$this->ion_auth->is_client($user->id) AND !$this->ion_auth->is_admin($user->id) AND $this->ion_auth->is_active($user->id)){ ?>
	<option value="<?php echo $user->id?>"><?php echo $user->username?></option>
	<?php }	}?>
</select>
<input  type="submit" class="btn btn-small btn-warning" value="Add Follower" data-loading-text="Loading..."/>
</form>
</div>
<?php }?>
</div>

</div>

</div>
<!-- Sub tasks -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('user/tasks/create_subtask/'.$tasks['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add New Sub Task</h3>
  </div>
  <div class="modal-body">
    <p>
	<input type="hidden" name="project_id" value="<?php echo $tasks['project_id'];?>"/>
	<input type="hidden" name="task_name" value="<?php echo $tasks['name'];?>"/>
	<input type="hidden" name="assigned_to" value="<?php echo $tasks['assigned_to'];?>"/>
	<label><b>Description</b></label>   
    <textarea placeholder="Add New Sub Task" class="span12" name="subtask" ></textarea>    
    <b>Time Spent </b><br />
	<input type="text" class="span1" value="00" name="hr" /> : <input type="text" name="min" class="span1" value="00" /> : <input type="text" class="span1" value="00" name="sec" />
	</p>
	
   <table width="100%" class="table">
   <tr>
    <td width="10%"><b>Priority</b></td>
    <td width="10%">
     <label class="radio"><input type="radio" id="radioBtn4" onmouseup="toggle(this);" value="low" name="priority" /><span class="low_box"></span> <span class="text-warning"> &nbsp; Low Priority </span></label>
     </td>
     <td width="10%">
    <label class="radio"><input type="radio" id="radioBtn5" onmouseup="toggle(this);" value="medium" name="priority" /><span class="medium_box"></span> <span class="text-success"> &nbsp; Medium Priority </span></label>
    </td>    
    <td width="10%">
    <label class="radio"><input type="radio" id="radioBtn6" onmouseup="toggle(this);" value="high" name="priority" /><span class="high_box"></span> <span class="text-error"> &nbsp; High Priority </span></label>
    </td>
    </tr>
    </table>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

<!-- Subtasks Heading -->
<div id="subtask_heading" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('user/tasks/create_subtask_heading/'.$tasks['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add New Subtask Heading</h3>
  </div>
  <div class="modal-body">
    <p>   
    <textarea placeholder="Add New Subtask Heading" class="span12" name="subtask"></textarea>	
    </p>
  
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

<script type="text/javascript">
$(document).ready(function(e) {
	// drag n drop	
	jQuery(function() {		
		jQuery("#contentLeft ul").sortable({  handle: '.flag_image', opacity: 0.6, cursor: 'move',  update: function() {			
			var order = jQuery(this).sortable("serialize") + '&action=updateRecordsListings'; 			
			jQuery.post("<?= site_url('user/tasks/sorting_subtasks');?>", order, function(theResponse){				
			}); 															 
		}								  
		});});
 
   var task_id = $('#task_id').val();	
	$.post('<?= site_url('user/tasks/check_is_achieved');?>',{taskid : task_id }, function(data) {	
	 if(data == 1)
	 {
	$('#bars').css('width','100%');
	$('#completed').html("100% Completed");
	$('#achieved').addClass('btn-success')
	$('#achieved').html('Unachieved'); 	 
	 }
	 else { $('#completed').html("0% Completed");} 
});

$.post('<?= site_url('user/tasks/check_is_completed');?>',{taskid : task_id }, function(msg) {	
	 if(msg == 1)
	 {
	$('#bars').css('width','100%');
	$('#completed').html("100% Completed");
	$('#closed').addClass('btn-success')
	$('#closed').html('Open');
	$('#achieved').hide();	 
	 }
	 else { $('#completed').html("0% Completed");} 
});

//check subtask is achieved or not 
var subtasks = $('#subtask').html();

var subtasks_heading = <?= count($subtasks)?> - subtasks ;
//alert(subtasks_heading)
var comnpleted_percentage =  Math.round(100 / subtasks) ;
//alert(comnpleted_percentage);
var completed_value = 0;
var checkcompleted = 0;
var checknotcompleted = -subtasks_heading;
var total_subtask_completed = 0;
<?php foreach ($subtasks as $subt) {?>
var subtask_id = $('#subtask_id<?= $subt->id?>').val()
//alert(subtask_id)
$.post('<?= site_url('user/tasks/check_subtask_is_achieved');?>',{subtask_id  : subtask_id }, function(subtask_msg) {
	// alert(subtask_msg)
	
	 if(subtask_msg==1)
	 {
		total_subtask_completed = total_subtask_completed + 1;				 			
	completed_value = parseInt(comnpleted_percentage) +parseInt( completed_value);	
	//alert(completed_value);
		$('#<?= $subt->id?>').html('Mark As Pending');
		$('#<?= $subt->id?>').addClass('text-success')
		$('#<?= $subt->id?>').css('font-weight','bold');
		$('#bars').css('width',completed_value+'%');
		$('#completed').html(completed_value +"% Completed");		
		//checkcompleted = 0;
		
		// adding the completed %
		//alert(completed_value)
		$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:completed_value,id:task_id}, function(completed) {
			//alert(completed)
			// location.reload(); 
		})
		
		//alert (total_subtask_completed);
		if(total_subtask_completed == subtasks)
		{
			$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:'100',id:task_id}, function(fullcompleted) {
			//alert(completed)
		})
			$('#bars').css('width','100%');
			$('#completed').html("100% Completed");	
		}
		
		
	 }
	// alert(completed_value);
	 else {		 
		 checknotcompleted  = (checknotcompleted + 1);
		 if(checknotcompleted == subtasks)	
		 {
			$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:'0',id:task_id}, function(notcompleted) {
			
		}) 
	 }
	 }
});
<?php }?>
	
});

// document ready function ends here

$('#submit_note').click(function () {	
	if(!$('#note').val())
	{
	alert('Note Field is Required');	
	}
	else {	
	var notes = $('#note').val();
	var task_id = $('#task_id').val();
	var type = $('#note_type').val();
	//alert(notes)
	//var attachment = $('#attachment').val();
	$.post('<?= site_url('user/tasks/add_note');?>',{note : notes , taskid : task_id, note_type: type }, function(data) {
	//alert(data)
 	$('#note').val("");
	$('#attachment').val("");
	$('#note_type').val("");
	  location.reload(); 
	 });
	}
	
	})

//Is Achieved
	
$('#achieved').click(function () {
	var task_id = $('#task_id').val();
	var check = $('#achieved').html();
	if( check == 'Unachieved' )
	{
	$.post('<?= site_url('user/tasks/task_unachieved');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','0%');
	$('#completed').html("0% Completed");
	$('#achieved').addClass('btn-primary')
	$('#achieved').html('Achieved');	
	});
	}
	//alert($('#achieved').html())
	else{	
	$.post('<?= site_url('user/tasks/task_achieved');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#achieved').addClass('btn-success')
	$('#achieved').html('Unachieved');	
	});
	}
})

$('#closed').click(function () {		
	var task_id = $('#task_id').val();
	var check = $('#closed').html();
	//alert(check);
	if( check == 'Open' )
	{
		//alert(check);
	$.post('<?= site_url('user/tasks/task_open');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','0%');
	$('#completed').html("0% Completed");
	$('#closed').addClass('btn-success')
	$('#closed').html('Close');	
	$('#achieved').show();
	});
	}
	else {
	$.post('<?= site_url('user/tasks/task_closed');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#closed').addClass('btn-success')
	$('#closed').html('Open');
	$('#achieved').hide(500); 
	});
	}
})
	
	function achieve(str)
	{
		var task_id = $('#task_id').val();
		var subtask_id = str;
		var subtasks = $('#subtask').html();
		var comnpleted_percentage =  parseInt(100 / subtasks) ;
		//alert(str);
		var id = "#"+str;
		if($(id).html() =='Mark As Pending'){
		$.post('<?= site_url('user/tasks/subtask_unachieved');?>',{subtask_id : subtask_id }, function(data) {		
				location.reload();
});	
	}
	else {
$.post('<?= site_url('user/tasks/subtask_achieved');?>',{subtask_id : subtask_id }, function(data) {		
			location.reload();
});
	}
		}
		
		// subtasks edit scripts
		
$('.edit_subtasks').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});

$('.multiple_subtask').live('keydown',function(e){
     var p = e.keyCode;	
	 var i = $('#insert_subtask p').size() + 1;	 
     if(p==13){       
		 $("#insert_subtask").append('<p> <input type="text" class="span9 multiple_subtask" name="m_subtask['+i+']" placeholder="(Delete) - To delete a row (Enter) - For new row" id=ms'+i+' />   <input type="text" class="span1 multiple_subtask" name="hr['+i+']" id="hr" value="00"/> : <input type="text" class="span1 multiple_subtask" name="min['+i+']" id="min" value="00"/> : <input type="text" class="span1 multiple_subtask" name="sec['+i+']" id="sec" value="00"/></p>');
		 $('#ms'+i+'').focus();
     }
	 else if(p==46 ){	 	
	 	if( i > 1)
				{
					$(this).parents('p').remove();
					i--;
					var rm = '#ms'+(i-1)+'';					
					$(rm).focus();					
				}
				return false;
	 }
 });
 
 $('#save_multiple').click(function(){
 	$('#multiple_form').submit();	
 });

$('.add_worksheet').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});

$('.add_todo').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});

$('.feedback').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});

$('.edit_note').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});

function toggle(radioBtn)
 {   
   if(radioBtn.checked)
   {
     setTimeout("disableRadio('"+radioBtn.id+"')",10);
   } else {
     radioBtn.checked = true;
   }
 }

function disableRadio(radioId) {
    el = window.document.getElementById(radioId);
    el.checked = false;
}

function time_spent(){
	var hr = $('#hr').val();
	var mins = $('#min').val();
	var sec = $('#min').val();
	var task_id = $('#task_id').val();
	$.post('<?= site_url('user/tasks/time_spent');?>',{hr : hr, mins: mins, id:task_id, sec:sec }, function(data) {
		//alert('asd');	
		location.reload();
}); 
}



function reply(note_id){
//alert(note_id);
	$('#reply_area'+note_id).show();
	/*note_id*/
}

function add_reply(nID){
	/*reply_desc*/
	reply_desc =  $('#reply_desc'+nID).val();
	$('#reply_desc'+nID).attr('readonly','readonly');
	$('#spinner').show(); 
	$.post('<?= site_url("user/tasks/post_reply");?>',{note_id:nID , replies : reply_desc }, function(replies) {			
			$('#reply_desc'+nID).removeAttr('readonly','readonly');
			 $('#reply_desc'+nID).val("");			
			$('#reply_area'+nID).hide();
			location.reload();
	})
}

/**
* code for disscussions of subtasks
* Author Arpan Pratik Kumar
* @ fedobe
*/
function open_discuss(url){	
myWindow = window.open(url,"_blank","width=700,height=650,toolbar=0,menubar=0,location=1,status=1,scrollbars=0,resizable=0,left=0,top=0");
myWindow.focus();
}

function show_multi(){
	$('#multisubtask').show(500);
}

$('.delete_feedback').click(function(){
	var Id = $(this).attr('rel');	
	 var conf = confirm('Do you want to delete this feedback ?? ');	
       if(conf){
		 $.post('<?= site_url("user/tasks/delete_feedback"); ?>',{id:Id}, function(replies) {
			location.reload();
			});	
	 }
})

/**
* Remove followers
* @author: Arpan Pratik Kumar
*/
 
function remove_follower(id,user_id){
	var removeid = '#follower'+id;
	var rname = $(removeid).attr('data-username');	
	 $.post('<?= site_url("user/tasks/remove_follower"); ?>',{id:id}, function(data) {			
			$(removeid).remove();
			/*$("#followers option[value='user_id']").remove();*/
			$("#followers").append('<option value="'+id+'">'+rname+'</option>');
			});	
}
 
</script>